package com.distribute.framework.model;

import com.distribute.framework.core.web.helper.Utils;
import java.lang.reflect.Field;
import java.util.Date; 
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;

import javax.annotation.Resource;

import com.distribute.framework.core.web.util.Page;
import com.distribute.framework.core.lang.*; 
import com.distribute.framework.core.web.helper.WebHelper.LzMap;
import com.distribute.framework.core.util.Function;
import com.distribute.framework.core.util.IbatisMap;
import com.distribute.framework.config.*;
import com.distribute.framework.plugin.*;

@namespace("business/activitytext")
public @caption("活动软文") @database(DatabaseNames.distribute_sys) @source("distribute_sys") @table("tb_activity_text") class TbActivityText implements java.io.Serializable
{
	private static final long serialVersionUID = 1l;
		
	
		
	private @caption("编号") @column("tbat_id")    @primary  @notnull  @note("  ") Long tbatId;// 主键 非空     
			
 			
 			
 		
	
		
	private @caption("品牌") @column("tbat_brand")      @relate("$tbatBrand") @RelateClass(Merchant.class)  @note("  ") Long tbatBrand;//     
			
 	private transient Merchant $tbatBrand;//关联对象[品牌信息]
 			
 			
 			
 		
	
		
	private @caption("内容") @column("tbat_content") @like  @hidden    @note("  ") String tbatContent;//     
			
 			
 			
 		
	
	 
	//默认构造函数
	public TbActivityText(){ 
	
	}
	
	//主键构造函数
	public TbActivityText(Long id){
		this.tbatId = id;
	}
	
	/**所有字段构造函数 
	 TbActivityText(
	 	Utils.getLong("brand")//品牌
	 	,Utils.getString("content")//内容
	 )
	**/
	public TbActivityText(Long tbatBrand,String tbatContent){
		
			
			
		this.tbatBrand=tbatBrand;
		
			
		this.tbatContent=tbatContent;
		
	}
	
	//设置非空字段
	public TbActivityText setNotNull(){
		
			
			
			
		return this;
	}
	
	
		
	/** 编号 [非空]       **/
	public TbActivityText tbatId(Long tbatId){
		this.tbatId = tbatId;
		this.setSeted(F.tbatId);
		return this;
	}
	
		
	/** 品牌  [Merchant]      **/
	public TbActivityText tbatBrand(Long tbatBrand){
		this.tbatBrand = tbatBrand;
		this.setSeted(F.tbatBrand);
		return this;
	}
	
		
	/** 内容        **/
	public TbActivityText tbatContent(String tbatContent){
		this.tbatContent = tbatContent;
		this.setSeted(F.tbatContent);
		return this;
	}
	
	
	
	/**
	* 克隆对象
	**/
	public TbActivityText clone(){
		TbActivityText clone = new TbActivityText();
		
			
			
		clone.tbatBrand=this.tbatBrand;
		
			
		clone.tbatContent=this.tbatContent;
		
		return clone;
	}
	
	
	
	
	
	/**
	 * 根据ID取活动软文
	 * @param id
	 * @return
	 */
	public static @api TbActivityText get(Long id){		
		return getTbActivityTextById(id);
	}
	
	
	/**
	 * 设置ID
	 * @param id
	 * @return
	 */
	public void setId(Long id){		
		this.tbatId = id;
	}
	
	
	/**
	 * 获取所有活动软文
	 * @return
	 */
	public static @api List<TbActivityText> list(Map params,Integer size){
		return getTbActivityTextList(params,size);
	}
	/**
	 * 获取活动软文分页
	 * @return
	 */
	public static @api Page<TbActivityText> page(Integer page,Integer size,Map params){
		return getTbActivityTextPage(page, size , params);
	}
	
	
	/**
	 * 根据查询条件取活动软文
	 * @param params
	 * @return
	 */
	public static @api TbActivityText Get(Map params){
		return getTbActivityText(params);
	}
	/**
	 * 获取活动软文数
	 * @return
	 */
	public static @api Long count(Map params){
		return getTbActivityTextCount(params);
	}
	/**
	 * 获取活动软文数
	 * @return
	 */
	public static @api <T> T eval(String eval,Map params){
		return getTbActivityTextEval(eval,params);
	}
	
	
	/**
	 * 获取活动软文图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> stats(Map params,C sumKey,C groupKey){
		return getTbActivityTextStats(params,sumKey,groupKey,-1);
	}
	/**
	 * 获取活动软文图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 分组的字段
	 * @param dateType 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> stats(Map params,C sumKey,C groupKey,int dateType){
		return getTbActivityTextStats(params,sumKey,groupKey,dateType);
	}
	
	
	/**
	 * 根据ID取活动软文
	 * @param id
	 * @return
	 */
	public static @api TbActivityText getTbActivityTextById(Long id){		
		return getTbActivityTextDao().getTbActivityTextById(id);
	}
	
	
	/**
	 * 获取id
	 * @return
	 */
	public Long getId(){
		return this.tbatId;
	}
	
	
	
	/**
	 * 根据ID取活动软文的标识键值
	 * @param id
	 * @return
	 */
	public static @api String getKeyValue(Object key){
		Long id = Utils.parseLong(key);	
		if(id==null || id.longValue()==0 ){
			
			return null;
			
		}
		String value = null;
		
		value = Cache.getValue(TbActivityText.class, id);
				
		if(value==null){
			TbActivityText tbActivityText = get(id);
			if(tbActivityText!=null){
				String strValue = tbActivityText.getTbatId$();
				
				
				Cache.setValue(TbActivityText.class, id ,strValue);
				
				value = strValue;
			}else{
				
				Cache.setValue(TbActivityText.class, id ,"{"+id+"}",30);
				
				value = "{"+id+"}";
			}
		}
		
		/************LAZY3Q_ID_KEYVALUE************/
		/************LAZY3Q_ID_KEYVALUE************/
		return value;
	}	
	
	
	/**
	 * 获取当前对象的键值
	 * @return
	 */
	public String getKeyValue(){
		
		/************LAZY3Q_CODE_KEYVALUE************/
		/************LAZY3Q_CODE_KEYVALUE************/
		String keyValue = this.getTbatId$();
		
		return keyValue;
	}
	
	
	/**
	 * 根据关键字精确查询活动软文对象
	 * @return
	 */
	public static @api TbActivityText find(String key){
		if(Utils.empty(key))return null;
		Map params = new HashMap();
		if(key.toLowerCase().startsWith("id:"))//如果查询条件以id:开头，则按ID查询
			params.put("tbatId", key.toLowerCase().replaceFirst("id:", ""));					
		else{//按标识查询，精确查询
			String strDefinex = "";
			
			strDefinex="(2=1 "+strDefinex+")";
			params.put("definex",strDefinex);
		}
		
		/************LAZY3Q_CODE_FIND************/
		/************LAZY3Q_CODE_FIND************/
		return TbActivityText.getTbActivityText(params);
	}
	
	
	/**
	 * 根据关键字查询活动软文
	 * @return
	 */
	public static @api List<Map> query(String key,int size,Map params,Boolean bObject){
		if(Utils.empty((String)params.get("asc")) && Utils.empty((String)params.get("desc")))//如果未传入排序字段
			params.put("desc","tbat_id");//那么，默认以主键降序，传给Dao层
		String strTerm=key;		
		if(!Utils.empty(strTerm)){
			if(strTerm.toLowerCase().startsWith("id:"))//如果查询条件以id:开头，则按ID查询
				params.put("tbatId", strTerm.toLowerCase().replaceFirst("id:", ""));					
			else//按标识查询，模糊查询请带%
			{
				String strDefinex = "";
				
				strDefinex="(2=1 "+strDefinex+")";
				params.put("definex",strDefinex);
			}
		}
		
		
		/************LAZY3Q_CODE_QUERY************/
		/************LAZY3Q_CODE_QUERY************/
			
		List<TbActivityText> list = page(0,size,params).getResult();
		
		/**
		* OK!取到数据拼成放入Map中，[{value,text,object:{...}},...]
		* value:数据ID，text:数据标识,object,整个对象
		**/
		List<Map> result = new java.util.ArrayList();
		for(TbActivityText tbActivityText:list){
			Map map = new HashMap();
			map.put("key",tbActivityText.getTbatId().toString());
			map.put("value", Utils.js(tbActivityText.getKeyValue()));
			if(bObject==true)
				map.put("object",tbActivityText);
			result.add(map);
		}
		
		
		/************LAZY3Q_AFTER_QUERY************/
		/************LAZY3Q_AFTER_QUERY************/
		
		return result;
	}
	
	
	
	/**
	 * 获取所有活动软文
	 * @return
	 */
	public static @api List<TbActivityText> getTbActivityTextList(Map params,Integer size){
		return getTbActivityTextDao().getTbActivityTextList(params,0,size);
	}
	
	/**
	 * 获取活动软文分页
	 * @return
	 */
	public static @api Page<TbActivityText> getTbActivityTextPage(Integer page,Integer size,Map params){
		if(page==null)page=0;
		if(size==null)size=20;
		return getTbActivityTextDao().getTbActivityTextPage(page, size , params);
	}
	
	/**
	 * 根据查询条件取活动软文
	 * @param params
	 * @return
	 */
	public static @api TbActivityText getTbActivityText(Map params){
		return getTbActivityTextDao().getTbActivityText(params);
	}
	
	/**
	 * 保存一个活动软文
	 * @param tbActivityText
	 * @return
	 */
	public static @api TbActivityText saveTbActivityText(TbActivityText tbActivityText){
		return getTbActivityTextDao().saveTbActivityText(tbActivityText);
	}
	
	/**
	 * 根据条件更新活动软文
	 * @param values
	 * @param params
	 */
	public static @api int updateTbActivityTextByConfirm(Map values, Map params){
		return getTbActivityTextDao().updateTbActivityTextByConfirm(values,params);
	}
	
	/**
	 * 修改一个活动软文
	 * @param tbActivityText
	 * @return
	 */
	public static @api int updateTbActivityText(TbActivityText tbActivityText){
		return getTbActivityTextDao().updateTbActivityText(tbActivityText);
	}
	
	/**
	 * 更新活动软文非空字段
	 * @param tbActivityText
	 */
	public static @api int updateTbActivityText$NotNull(TbActivityText tbActivityText){
		return getTbActivityTextDao().updateTbActivityText$NotNull(tbActivityText);
	}
	
	/**
	 * 获取活动软文数
	 * @return
	 */
	public static @api Long getTbActivityTextCount(Map params){
		return getTbActivityTextDao().getTbActivityTextCount(params);
	}
		
		
	/**
	 * 获取活动软文自定义求和表达式,比如求和:eval="sum(id)"
	 * @return
	 */	
	public static @api <T> T getTbActivityTextEval(String eval,Map params){
		return getTbActivityTextDao().getTbActivityTextEval(eval,params);
	}
	
	
	/**
	 * 获取活动软文图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 分组的字段
	 * @param dateType 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> getTbActivityTextStats(Map params,C sumKey,C groupKey,int dateType){
		//TODO:图表统计功能未实现
		
		Map<String,Object> groups=new HashMap();//要分组的字段
		Map<String,Object> sums=new HashMap();//要统计的字段
		
		String[][] dateFormats=new String[][]{
				null,
				new String[]{"%Y","yyyy年","Y"},
				new String[]{"%Y-%m","yyyy年MM月","M"},
				new String[]{"%Y%U","yyyy年第ww周","W"},
				new String[]{"%Y-%m-%d","yyyy年MM月dd日","D"},
				new String[]{"%Y-%m-%d %H","yyyy年MM月dd日 HH点","H"},
				new String[]{"%m","MM月"},
				new String[]{"%d","dd号"},
				new String[]{"%H","HH点"} 
		};
		
		//获取要分组的字段，放入Map中
		if(dateType>0){
			groups.put(groupKey.toString(),"DATE_FORMAT({key},'"+dateFormats[dateType][0]+"')");
		}else{
			groups.put(groupKey.toString(),"{key}");
		}
		if(dateType<6 && dateType>0){ 
			params.put("asc", groupKey.toString()); 
			if(params.get(groupKey.name()+"Start")==null){
				params.put(groupKey.name()+"Start", Utils.date(new Date(), -24, dateFormats[dateType][2]));
			}
		}
		
		
		//获取要统计的字段，放入Map中
		if(sumKey.toString().equals("count")){
			sums.put(sumKey.toString(),"count(*)");
		}else{
			sums.put(sumKey.toString(),"sum({key})");
		}
		
		List<Map> list = getTbActivityTextDao().getTbActivityTextStats(params,groups,sums);
		
		List<Map> result = new ArrayList();
		for(Map m:list){
			Map map = new HashMap();
			Object value = m.get(sumKey.toString());
			Object name = null;
			Object groupValue = m.get(groupKey.toString());
			if(dateType>0){
				name = Utils.date(Utils.parseDate(groupValue), dateFormats[dateType][1]);
			}else{
				try{
					java.lang.reflect.Method method = TbActivityText.class.getMethod("get"+Utils.ForMat(groupKey.toString())+"$");
					method.setAccessible(true);
					name = method.invoke(TbActivityText.fromMap(m));
				}catch(Exception ex){
					ex.printStackTrace();
				}
			}
			map.put("name", name);
			map.put("value", value);
			result.add(map);
		}
		return result;
	}
	
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static int updateTbActivityText(Map set,Map where){
		if(set.isEmpty())throw new RuntimeException("set为空");
		if(where.isEmpty())throw new RuntimeException("where为空");
		where.put("confirm", "1");
		return getTbActivityTextDao().updateTbActivityTextByConfirm(set, where);
	}
	
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static void deleteTbActivityText(Map where){
		if(where.isEmpty())throw new RuntimeException("where为空");
		where.put("confirm", "1");
		getTbActivityTextDao().deleteTbActivityTextByConfirm(where);
	}
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static void delete(Long id){
		if(id==null)throw new RuntimeException("id为空");
		
		getTbActivityTextDao().deleteTbActivityTextById(id);
		
	}
	
	
	/**
	 * 保存活动软文对象
	 * @param params
	 * @return
	 */
	public TbActivityText save(){
		if(this.getTbatId()!=null)
			getTbActivityTextDao().updateTbActivityText(this);
		else
			return getTbActivityTextDao().saveTbActivityText(this);
		return this;
	}
	
	
	/**
	 * 更新活动软文对象的非空字段,注意跟Service里面的update不一样哦
	 * @param params
	 * @return
	 */
	public int update(){
		return getTbActivityTextDao().updateTbActivityText$NotNull(this);
	}
	
	
	/**
	 * 删除
	 * @param params
	 * @return
	 */
	public void delete(){
		
			getTbActivityTextDao().deleteTbActivityTextById(this.getTbatId());
	}
	
	/**
	 * 执行事务
	 * @param function
	 */
	public static <T> T execute(Function function){
		return getTbActivityTextDao().executeTransaction(function);
	}

	
	
	/*******************************编号**********************************/	
	/**
	* 编号 [非空]      
	**/
	public Long getTbatId(){
		
		if(this.tbatId!=null){
			return this.tbatId;
		}
		
		return this.tbatId;
	}
	/**
	* 获取编号格式化(toString)
	**/
	public String getTbatId$(){
		String strValue="";
	
	
		 strValue=Utils.string(this.getTbatId());
	 
	 	 return strValue;
	}
	/**
	* 根据编号反格式化
	**/
	public void setTbatId$(String strValue){
		if(Utils.empty(strValue)){
			this.tbatId=null;
			return;
		}
	
	
	 	this.tbatId=Utils.parseLong(strValue);
	 
	}
	
	/**
	* 编号 [非空]      
	**/
	public void setTbatId(Long tbatId){
		this.tbatId = tbatId;
		
		this.setSeted(F.tbatId);
		
	}
	
	
	
	
	
	
	
	
	
	
 	
 	
	
	
	
	
	
 	
 	
 	
	
	
	/*******************************品牌**********************************/	
	/**
	* 品牌  [Merchant]     
	**/
	public Long getTbatBrand(){
		
		if(this.tbatBrand!=null){
			return this.tbatBrand;
		}
		
		return this.tbatBrand;
	}
	/**
	* 获取品牌格式化(toString)
	**/
	public String getTbatBrand$(){
		String strValue="";
	
	
		 
		if(this.getTbatBrand()!=null){
			
				strValue+=Utils.string(Merchant.getKeyValue(this.getTbatBrand()));
			
		}			
		 
	 
	 	 return strValue;
	}
	/**
	* 根据品牌反格式化
	**/
	public void setTbatBrand$(String strValue){
		if(Utils.empty(strValue)){
			this.tbatBrand=null;
			return;
		}
	
	
		 
		Merchant item = Merchant.find(strValue);
		if(item!=null){
			
			this.tbatBrand = Utils.parseLong(item.getId());
			
		}
		 
	 
	}
	
	/**
	* 品牌  [Merchant]     
	**/
	public void setTbatBrand(Long tbatBrand){
		this.tbatBrand = tbatBrand;
		
		this.setSeted(F.tbatBrand);
		
	}
	
	
		 
	
	
	
	
	
	
	
	
	
 	
 	
	
	
	
	
	
 	
 		
	/**
	* 获取关联对象[品牌信息]
	**/	 			
 	public Merchant get$tbatBrand(){
 		if(this.$tbatBrand!=null)
 			return this.$tbatBrand;
 		com.distribute.framework.model.Merchant merchant = null;
		if(this.getTbatBrand()!=null){
		
 			merchant = Merchant.get(this.getTbatBrand());
 		
 		}
 		return merchant;
	}
	
 	
	
	
	/*******************************内容**********************************/	
	/**
	* 内容       
	**/
	public String getTbatContent(){
		
		if(this.tbatContent!=null){
			return this.tbatContent;
		}
		
		return this.tbatContent;
	}
	/**
	* 获取内容格式化(toString)
	**/
	public String getTbatContent$(){
		String strValue="";
	
	
		 strValue=Utils.string(this.getTbatContent());
	 
	 	 return strValue;
	}
	/**
	* 根据内容反格式化
	**/
	public void setTbatContent$(String strValue){
		if(Utils.empty(strValue)){
			this.tbatContent=null;
			return;
		}
	
	
		this.tbatContent=strValue;
	 
	}
	
	/**
	* 内容       
	**/
	public void setTbatContent(String tbatContent){
		this.tbatContent = tbatContent;
		
		this.setSeted(F.tbatContent);
		
	}
	
	
	
	
	
	
	
	
	
	
 	
 	
	
	
	
	
	
 	
 	
 	
	
	
	
	/************LAZY3Q_DEFINE_CODE************/
	/************LAZY3Q_DEFINE_CODE************/	
	
	
	/**
	 * 触发器
	 */
	public static void on(Trigger.Index index,final Notify.Listener listener,Trigger.Type... types){
		Notify.on(TbActivityText.class, index, listener, types);
	}
	public static void on(final Notify.Listener listener,String type){
		Notify.on(TbActivityText.class, listener, type);
	}
	/**
	 * 当修改字段时
	 * @param filedName
	 * @param listener
	 */
	public static void on(String filedName,final Notify.Listener listener){
		Notify.on(TbActivityText.class, listener, filedName);
	}
	/**
	 * 当修改字段为某值时
	 * @param filedName
	 * @param value
	 * @param listener
	 */
	public static void on(String filedName,Object value,final Notify.Listener listener){
		if(value==null)return;
		Notify.on(TbActivityText.class, listener, filedName+"."+Utils.md5(""+value));
	}
	public void notify(String type){
		Trigger.on(TbActivityText.class,type, this);
	}
	
	
	/**
	 * 用来获取当有字段关联对象时的获取方式,调用如${TbActivityText.obj.filedName}
	 * 因为有些变态的模板语言不能识别$，所以不能以${TbActivityText.$filedName}获取关联对象
	 */
	public Map getObj(){
		return new HashMap(){
			@Override
			public Object get(Object key) {
				try {
					return TbActivityText.class.getMethod("get$"+Utils.forMat(key.toString())).invoke(TbActivityText.this);
				} catch (Exception e) {
					e.printStackTrace();
				}
				return null;
			}
		};
	}
	/**
	 * 用来获取某字段格式化的获取方式,调用如${TbActivityText.fmt.filedName}
	 * 因为有些变态的模板语言不能识别$，所以不能以${TbActivityText.filedName$}获取某字段格式化
	 */
	public Map getFmt(){
		return new HashMap(){
			@Override
			public Object get(Object key) {
				try {
					return TbActivityText.class.getMethod("get"+Utils.ForMat(key.toString()+"$")).invoke(TbActivityText.this);
				} catch (Exception e) {
					e.printStackTrace();
				}
				return null;
			}
		};
	}
	/**
	 * 获取查询参数链式串
	 * @return
	 */
	public static @Deprecated M where(){ return new M(0); }
	public static @Deprecated M m(){ return new M(0); }
	public static M where = new M(0,true);
	public static @database(DatabaseNames.distribute_sys) class M extends IbatisMap{
		int type = 0; 
		M linked = null;
		Boolean proxy = false;
		public M set = null;
		public M(int type){
			this.type = type;
			if(this.type==0){
				set = new M(1,true);
				set.linked = this;
			}
		};
		public M(int type,Boolean proxy){
			this.type = type;
			this.proxy=proxy;
		};
		public M proxy(){
			M m = new M(this.type);//当前的对像
			if(this.type==0){
				m.set = new M(1,true);//set对象
				m.set.linked = m;
			}else{
				m.linked=this.linked;
				this.linked.linked=m;
			}
			return m;
		}
		public @Deprecated M set(){			
			M m = this;
			m.linked=new M(1);
			m.linked.linked=m;
			return m.linked;
		};
		
		public M on(IbatisMap value,C column,String joinColumn){if(proxy)return proxy().on(value,column,joinColumn);this.put(value.getClass().getDeclaringClass().getSimpleName(), value);value.put("on", column.toString());value.put("to", joinColumn);return this;};
		
		
			
		
		/** 编号 [非空]       **/
		public M tbatId(Object tbatId){if(proxy)return proxy().tbatId(tbatId);  this.put("tbatId", tbatId);return this;};
	 	/** and tbat_id is null */
 		public M tbatIdNull(){if(proxy)return proxy().tbatIdNull();if(this.get("tbatIdNot")==null)this.put("tbatIdNot", "");this.put("tbatId", null);return this;};
 		/** not .... */
 		public M tbatIdNot(){if(proxy)return proxy().tbatIdNot();this.put("tbatIdNot", "not");return this;};
 		public M tbatIdNotNull(){if(proxy)return proxy().tbatIdNotNull();this.put("tbatIdNot", "not");this.put("tbatId", null);return this;};
 		public M tbatIdNot(Object tbatId){if(proxy)return proxy().tbatIdNot(tbatId);this.put("tbatIdNot", "not");this.put("tbatId", tbatId);return this;};
	 		
		/** and tbat_id <= ? */
		public M tbatIdMin(Object min){if(proxy)return proxy().tbatIdMin(min);this.put("tbatIdMin", min);return this;};
		/** and tbat_id >= ? */
		public M tbatIdMax(Object max){if(proxy)return proxy().tbatIdMax(max);this.put("tbatIdMax", max);return this;};
			
			
		public M tbatIdIn(String ids){
			if(proxy)return proxy().tbatIdIn(ids);  this.put("tbatIdIn", ids);return this;
		};	
 			
		
			
	 	
			
		public M tbatBrand$on(Merchant.M value){if(proxy)return proxy().tbatBrand$on(value);this.put("TbatBrand", value);value.put("on", "tbat_brand");return this;};
 				
 			
		
		/** 品牌  [Merchant]      **/
		public M tbatBrand(Object tbatBrand){if(proxy)return proxy().tbatBrand(tbatBrand);  this.put("tbatBrand", tbatBrand);return this;};
	 	/** and tbat_brand is null */
 		public M tbatBrandNull(){if(proxy)return proxy().tbatBrandNull();if(this.get("tbatBrandNot")==null)this.put("tbatBrandNot", "");this.put("tbatBrand", null);return this;};
 		/** not .... */
 		public M tbatBrandNot(){if(proxy)return proxy().tbatBrandNot();this.put("tbatBrandNot", "not");return this;};
 		public M tbatBrandNotNull(){if(proxy)return proxy().tbatBrandNotNull();this.put("tbatBrandNot", "not");this.put("tbatBrand", null);return this;};
 		public M tbatBrandNot(Object tbatBrand){if(proxy)return proxy().tbatBrandNot(tbatBrand);this.put("tbatBrandNot", "not");this.put("tbatBrand", tbatBrand);return this;};
	 		
			
		public M tbatBrandIn(String ids){
			if(proxy)return proxy().tbatBrandIn(ids);  this.put("tbatBrandIn", ids);return this;
		};	
 			
		
			
	 	
			
		
		/** 内容        **/
		public M tbatContent(Object tbatContent){if(proxy)return proxy().tbatContent(tbatContent);  this.put("tbatContent", tbatContent);return this;};
	 	/** and tbat_content is null */
 		public M tbatContentNull(){if(proxy)return proxy().tbatContentNull();if(this.get("tbatContentNot")==null)this.put("tbatContentNot", "");this.put("tbatContent", null);return this;};
 		/** not .... */
 		public M tbatContentNot(){if(proxy)return proxy().tbatContentNot();this.put("tbatContentNot", "not");return this;};
 		public M tbatContentNotNull(){if(proxy)return proxy().tbatContentNotNull();this.put("tbatContentNot", "not");this.put("tbatContent", null);return this;};
 		public M tbatContentNot(Object tbatContent){if(proxy)return proxy().tbatContentNot(tbatContent);this.put("tbatContentNot", "not");this.put("tbatContent", tbatContent);return this;};
	 		
			
		
			
	 	
	 	public M add(String key, Object value) {if(proxy)return proxy().add(key,value);this.put(key, value);return this;}
	 	public M add(F key, Object value) {if(proxy)return proxy().add(key,value);this.put(key.toString(), value);return this;}
	 	
	 	public M desc(C key) {if(proxy)return proxy().desc(key);this.put("desc", key.column);return this;}
	 	public M asc(C key) {if(proxy)return proxy().asc(key);this.put("asc", key.column);return this;}
	 	public M desc(String sql) {if(proxy)return proxy().desc(sql);this.put("desc", sql);return this;}
	 	public M asc(String sql) {if(proxy)return proxy().asc(sql);this.put("asc", sql);return this;}
	 	public M definex(String sql) {if(proxy)return proxy().definex(sql);this.put("definex", sql);return this;}
	 	
	 	/** 获取所有活动软文 **/
		public @api List<TbActivityText> list(Integer size){			
			return getTbActivityTextList(this,size);
		}
		/** 获取活动软文分页 **/
		public @api Page<TbActivityText> page(Integer page,Integer size){			
			return getTbActivityTextPage(page, size , this);
		}
		/** 根据查询条件取活动软文 **/
		public @api TbActivityText get(){			
			return getTbActivityText(this);
		}
		/** 获取活动软文数 **/
		public @api Long count(){			
			return getTbActivityTextCount(this);
		}
		/** 获取活动软文表达式 **/
		public @api <T> T eval(String strEval){			
			return getTbActivityTextEval(strEval,this);
		}
		
		/** 获取活动软文统计 **/
		public @api List<Map> stats(C sumKey,C groupKey,int dateType){			
			return getTbActivityTextStats(this,sumKey,groupKey,dateType);
		}
		/** 获取活动软文统计 **/
		public @api List<Map> stats(C sumKey,C groupKey){			
			return getTbActivityTextStats(this,sumKey,groupKey,-1);
		}
		
		/** 根据条件更新 **/
		public @api int update(){			
			M where = null;
			M set = null;
			if(this.type==0){
				if(this.linked==null)throw new RuntimeException("未发set");
				where = this;
				set = this.linked;
			}else{
				if(this.linked==null)throw new RuntimeException("未发where条件");
				set = this;
				where = this.linked;
			}
			return updateTbActivityText(set,where);
		}
		/** 根据条件删除 **/
		public @api void delete(){			
			deleteTbActivityText(this);
		}
	}
	
	public static class Param extends M{
		public Param(int type) {
			super(type);
		}
		public Param(int type, Boolean proxy) {
			super(type, proxy);
		}
	}
	
	/** 对象的字段描述 **/
	public static class F{
		
			
		/** 编号 [非空]       **/
		public final static @type(Long.class)  String tbatId="tbatId";
	 			
			
	 	
			
		/** 品牌  [Merchant]      **/
		public final static @type(Long.class)  String tbatBrand="tbatBrand";
	 			
			
	 	
			
		/** 内容        **/
		public final static @type(String.class) @like String tbatContent="tbatContent";
	 			
			
	 	
	 	public static String get(String name){
			try {
				Field field = F.class.getField(name);
				if(field!=null)
					return field.get(null).toString();
			} catch (Exception e) {
				//e.printStackTrace();
			}
			return null;
		}
	}
	
	
	
	/** 对象的数据库字段描述 **/
	public static enum C{
		
		tbatId("tbat_id"),
		tbatBrand("tbat_brand"),
		tbatContent("tbat_content"),
		count("count");
		String column;
		C(String column){
			this.column = column;
		}
		public String toString(){
			return this.column;
		}
		public static String get(String name){
			try {
				Field field = C.class.getField(name);
				if(field!=null)
					return field.get(null).toString();
			} catch (Exception e) {
				//e.printStackTrace();
			}
			return null;
		}
	}
	
	
	
	
	/**
	* 获取活动软文数据
	**/
	public static Object getData(Object param){
		if(param==null)
			return null;
		Object value = null;
		if(param.getClass()==Long.class)
			value = TbActivityText.get((Long)param);
		else if(param instanceof java.util.Map){
			java.util.Map params = (Map) param;
			if(params.get("size")==null)
				value = TbActivityText.getTbActivityText(params);
			else
				value = TbActivityText.getTbActivityTextList(params, (Integer) params.get("size"));
		}else if(param.getClass()==Long.class )
			value =  TbActivityText.where().tbatId(param).get();
		else if(!Utils.empty(param.toString()))
			value = TbActivityText.get(Long.valueOf(param.toString()));
		return value;
	}
	
	/**对象转json**/
	public Map toJSON(){
		return toJSON(false);
	}
	public Map toJSON(boolean simple){
		return toJSON(simple,0);
	}
	public Map toJSON(boolean simple,int step){
		Map map = new HashMap();
		map.put("id",this.getTbatId());
	
		Utils.fms(map,simple?"id":"tbatId",this.getTbatId(),this.getTbatId$());
		
			
 		
	
		Utils.fms(map,simple?"brand":"tbatBrand",this.getTbatBrand(),this.getTbatBrand$());
		
			
 		
	
		Utils.fms(map,simple?"content":"tbatContent",this.getTbatContent(),this.getTbatContent$());
		
			
 		
	
		if(this.suffix!=null)map.put("suffix", this.suffix);
		
		/************LAZY3Q_DEFINE_TOJSON************/
		/************LAZY3Q_DEFINE_TOJSON************/
		return map;
	}
	/**对象转map**/
	public Map toMap(){
		Map map = new HashMap();
	
		map.put("tbatId",this.getTbatId());
 		
	
		map.put("tbatBrand",this.getTbatBrand());
 		
	
		map.put("tbatContent",this.getTbatContent());
 		
	
		map.put("suffix", this.suffix);
		
		/************LAZY3Q_DEFINE_TOMAP************/
		/************LAZY3Q_DEFINE_TOMAP************/
		return map;
	}
	/**map转对象**/
	public static TbActivityText fromMap(Map map){
		TbActivityText tbActivityText = new TbActivityText();
	
		tbActivityText.tbatId = Utils.parseLong(map.get("tbatId"));
 		
	
		tbActivityText.tbatBrand = Utils.parseLong(map.get("tbatBrand"));
 		
	
		tbActivityText.tbatContent = Utils.parseString(map.get("tbatContent"));
 		
	
		return tbActivityText;
	}
	
	
	/**字段设置标记队列**/
	private Map<String,Boolean> seted=new HashMap();
	public Boolean getSeted(String key){
		return seted.get(key);
	}
	public void setSeted(String key){
		seted.put(key,true);
	}
	/**同步未set的字段**/
	public void mergeSet(TbActivityText old){
		Field[] fields = this.getClass().getDeclaredFields();
		try {
			for(Field field:fields){
				String key = field.getName();
				if(seted.get(key)==null && field.getAnnotation(column.class)!=null){
					field.setAccessible(true);
					field.set(this, field.get(old));					
				}
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	
		
	/**自定义变量存储**/
	private Map values=new HashMap();
	public Map getValues(){
		return values;
	}
	public void setValues(String name,Object value){
		values.put(name,value);
	}
	
	/**分表时的表名后缀**/
	private String suffix;
	public String getSuffix() {
		return suffix;
	}
	public void setSuffix(String suffix) {
		this.suffix = suffix;
	}
	
	
	/**获取数据库名称**/
	public static String getDataBaseName(){
		return Utils.config("spring.datasource.distribute_sys.name");
	}
	
	
	public static String getIcon(){
		return "";
	}
	public static String getIconfont(){
		return "icon-libreoffice";
	}
	public static enum ACT{
		列表,添加,修改,详情
	};
	public static String getUrl(ACT act,TbActivityText.M params){
		if(params==null)params=new TbActivityText.M(0);
		params.remove("joins");
		params.remove("definexs");
		params.remove("distinct");
		String strUrl = "/admin/business/activitytext.edit.html?";
		if(params.get("tbatId")!=null){
			strUrl+="&id="+Utils.encode(""+params.get("tbatId"),Utils.UTF8);
		}
		if(act==ACT.列表){
			strUrl = "/admin/business/activitytext.html?1=1";
		
		}else if(act==ACT.添加){
			strUrl+="&edittype=insert";
		
		
		}else if(act==ACT.修改){
			strUrl+="&edittype=update";
		
		}else if(act==ACT.详情){
			strUrl+="&edittype=detail";
		
		}		
		if(params!=null){
			for(Object key:params.keySet()){
				strUrl+="&"+key+"="+Utils.encode(""+params.get(key),Utils.UTF8)+"";
			}
		}
		return strUrl;
	}
	public String getDetailUrl(){
		return this.getUrl(ACT.详情, where.tbatId(this.getId()));
	}
	
	/**
	* 转跳到当前地址
	**/
	public static Protocol redirect(TbActivityText.ACT act,TbActivityText.M params){
		Protocol protocol = Protocol.create(true,null,"ACT_REDIRECT");
		protocol.set("url",TbActivityText.getUrl(act, params));
		return protocol;
	}
	/**
	* 打开一个新的tab页面
	**/
	public static Protocol href(TbActivityText.ACT act,TbActivityText.M params){
		Protocol protocol = Protocol.create(true,null,"ACT_HREF");
		protocol.set("url",TbActivityText.getUrl(act, params));
		protocol.set("title",act.name());
		return protocol;
	}
	/**
	* 显示一个消息框，并且关闭当前的对话框
	**/
	public static Protocol message(String message){
		Protocol protocol = Protocol.create(true,null,"ACT_MESSAGE");
		protocol.set("message",message);
		return protocol;
	}
	
	
	static com.distribute.framework.dao.ITbActivityTextDao getTbActivityTextDao(){
		return Utils.getBean("tbActivityTextDao");
	};
	
}